package com.ptt.sqm.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.serialization.PropertyInfo;

import android.app.Activity;
import android.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.SlidingDrawer;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

import com.ptt.sqm.component.PagingScrollView;
import com.ptt.sqm.component.ScrollViewListener;
import com.ptt.sqm.component.Search;
import com.ptt.sqm.component.SpinnerObject;
import com.ptt.sqm.model.AssessItem;
import com.ptt.sqm.model.AssessItemList;
import com.ptt.sqm.model.AssessSuggestion5034;
import com.ptt.sqm.model.ReportCache;
import com.ptt.sqm.model.SearchAssessCache;
import com.ptt.sqm.model.SearchAssessList;
import com.ptt.sqm.model.SuggestionReport;
import com.ptt.sqm.model.SuggestionReportList;
import com.ptt.sqm.model.SummaryAssess;
import com.ptt.sqm.util.AppUtil;
import com.ptt.sqm.util.WidgetUtil;
import com.ptt.sqm.ws.AsyncResponse;
import com.ptt.sqm.ws.DefaultTask;
import com.ptt.sqm.ws.DownloadCall;
import com.ptt.sqmonmobile.R;

/**
 * A simple {@link Fragment} subclass. Activities that contain this fragment
 * must implement the {@link ReportAssessFragment.OnFragmentInteractionListener}
 * interface to handle interaction events. Use the
 * {@link ReportAssessFragment#newInstance} factory method to create an instance
 * of this fragment.
 * 
 */
public class ReportAssessFragment extends DefaultFragment implements AsyncResponse {

	// Create Webservice class object
	private DefaultTask mTask = null;

	private DownloadCall downloadCall = null;

	private static ReportAssessFragment fragment;

	private OnFragmentInteractionListener mListener;

	private SuggestionReportList suggestRptList;

	private Search search;

	private ReportCache reportCache = new ReportCache();

	private View mProgressView;

	private View mContentView;

	private View mProgressSearchView;

	private View mContentSearchView;

	private int currentPage;

	private int maxPage;

	public static ReportAssessFragment newInstance(int sectionNumber, SuggestionReportList suggestRptList) {
		fragment = new ReportAssessFragment(suggestRptList);
		Bundle args = new Bundle();
		args.putInt(AppUtil.ARG_SECTION_NUMBER, sectionNumber);
		fragment.setArguments(args);

		return fragment;
	}

	public ReportAssessFragment(SuggestionReportList suggestRptList) {
		// Required empty public constructor
		this.suggestRptList = suggestRptList;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);

		TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
		mNoData.setVisibility(TextView.INVISIBLE);

		// Loading...
		mProgressView = view.findViewById(R.id.progress);
		mContentView = view.findViewById(R.id.container);
		mProgressSearchView = view.findViewById(R.id.vertical_data_progress);
		mContentSearchView = view.findViewById(R.id.vertical_data);

		// Search Sliding
		final SlidingDrawer slide = (SlidingDrawer) view.findViewById(R.id.search_slider);

		final ViewGroup grid = (ViewGroup) slide.findViewById(R.id.content);

		// Top-to-bottom
		grid.setRotation(180);
		grid.setVisibility(LinearLayout.VISIBLE);
		slide.setRotation(180);

		// Search Input
		search = Search.getInstance(getActivity(), getView(), gson, com);
		search.showSearchForReport(getActivity(), getView());

		Button searchBtn = (Button) view.findViewById(R.id.seach_btn);
		Button clearBtn = (Button) view.findViewById(R.id.clear_btn);
		searchBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				boolean isChosen = false;
				String year = "", project = "", zone = "", station = "", type = "", cycle = "";
				Spinner yearSpin = (Spinner) getView().findViewById(R.id.year_assess);
				Spinner projSpin = (Spinner) getView().findViewById(R.id.project_assess);
				Spinner cycleSpin = (Spinner) getView().findViewById(R.id.cycle_assess);
				Spinner divSpin = (Spinner) getView().findViewById(R.id.div_assess);
				Spinner deptSpin = (Spinner) getView().findViewById(R.id.dept_assess);
				Spinner zoneSpin = (Spinner) getView().findViewById(R.id.zone_assess);
				Spinner typeSpin = (Spinner) getView().findViewById(R.id.type_assess);
				if (yearSpin.getSelectedItemPosition() != 0) {
					year = ((SpinnerObject) yearSpin.getSelectedItem()).getValue();
					isChosen = true;
				}
				if (projSpin.getSelectedItemPosition() != 0) {
					project = ((SpinnerObject) projSpin.getSelectedItem()).getValue();
					isChosen = true;
				}
				if (cycleSpin.getSelectedItemPosition() != 0) {
					cycle = ((SpinnerObject) cycleSpin.getSelectedItem()).getValue();
					isChosen = true;
				}
				if (zoneSpin.getSelectedItemPosition() != 0) {
					zone = ((SpinnerObject) zoneSpin.getSelectedItem()).getValue();
					isChosen = true;
				} else if (deptSpin.getSelectedItemPosition() != 0) {
					zone = ((SpinnerObject) deptSpin.getSelectedItem()).getValue();
					isChosen = true;
				} else if (divSpin.getSelectedItemPosition() != 0) {
					zone = ((SpinnerObject) divSpin.getSelectedItem()).getValue();
					isChosen = true;
				}
				if (typeSpin.getSelectedItemPosition() != 0) {
					type = ((SpinnerObject) typeSpin.getSelectedItem()).getValue();
					isChosen = true;
				}
				if (search.shipToSelected != null && search.shipToSelected.length() != 0) {
					isChosen = true;
				}
				if (!isChosen) {
					Toast.makeText(getActivity(), getString(R.string.alert_at_least_one_choice), Toast.LENGTH_SHORT).show();
					return;
				}
				station = search.shipToSelected;

				slide.close();
				WidgetUtil.showProgress(mContentView, mProgressView, true);

				resetHeader();

				getReportService(year, project, cycle, zone, station, type);
			}
		});

		clearBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				clearSearchAssess();
			}
		});

		// TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
		final ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);

		if (suggestRptList != null) {
			generateReport();
			slide.open();
			slide.close();
		} else {
			mNoData.setVisibility(TextView.INVISIBLE);
			mHasData.setVisibility(ViewGroup.GONE);
			slide.open();
		}

		if (slide.isOpened()) {
			ImageView handle = (ImageView) slide.findViewById(R.id.handle);
			handle.setImageResource(R.drawable.show);

			WidgetUtil.setupSlideOpened(getActivity(), mNoData, slide);
		}

		slide.setOnDrawerCloseListener(new OnDrawerCloseListener() {

			@Override
			public void onDrawerClosed() {
				// TODO Auto-generated method stub
				grid.setVisibility(LinearLayout.INVISIBLE);
				ImageView handle = (ImageView) slide.findViewById(R.id.handle);
				handle.setImageResource(R.drawable.hide);

				WidgetUtil.setupSlideClosed(getActivity(), mHasData);
			}
		});

		slide.setOnDrawerOpenListener(new OnDrawerOpenListener() {

			@Override
			public void onDrawerOpened() {
				// TODO Auto-generated method stub
				ImageView handle = (ImageView) slide.findViewById(R.id.handle);
				handle.setImageResource(R.drawable.show);

				WidgetUtil.setupSlideOpened(getActivity(), mHasData, slide);
			}
		});

	}

	private void generateReport() {
		// TODO Auto-generated method stub
		final TableLayout table = (TableLayout) getView().findViewById(R.id.rpt_sgt_table);

		int count = 0;
		for (SuggestionReport suggestRpt : suggestRptList.SuggestionReport) {
			final TableRow row = (TableRow) LayoutInflater.from(getActivity()).inflate(R.layout.report_assess_row, null);

			String rptStation = "";
			if ((AppUtil.toString(suggestRpt.StationName)).length() != 0) {
				rptStation = AppUtil.toString(suggestRpt.StationId) + AppUtil.SPACE + AppUtil.toString(suggestRpt.StationName) + AppUtil.SPACE + AppUtil.toString(suggestRpt.Amphur) + AppUtil.SPACE
					+ AppUtil.toString(suggestRpt.Province);
			}
			String rptProject = AppUtil.toString(suggestRpt.ProjectName);
			String rptCycle = AppUtil.toString(suggestRpt.AssessBetween);
			String rptDate = AppUtil.toString(suggestRpt.Assessdate);
			String rptType = AppUtil.toString(suggestRpt.AssessUserType);
			String rptSubject = AppUtil.toString(suggestRpt.AssessSubjectName);
			String rptProblem = AppUtil.toString(suggestRpt.AssessSuggestionDesc);
			String rptSuggest = AppUtil.toString(suggestRpt.AssessSuggestionDetail);
			String rptUser = AppUtil.toString(suggestRpt.UserFullName) + AppUtil.SPACE + AppUtil.toString(suggestRpt.UserTel);
			String rptOwner = AppUtil.toString(suggestRpt.OwnerName) + AppUtil.SPACE + AppUtil.toString(suggestRpt.OwnerTel);

			((TextView) row.findViewById(R.id.rpt_sgt_station)).setText(rptStation);
			((TextView) row.findViewById(R.id.rpt_sgt_project)).setText(rptProject);
			((TextView) row.findViewById(R.id.rpt_sgt_cycle)).setText(rptCycle);
			((TextView) row.findViewById(R.id.rpt_sgt_date)).setText(rptDate);
			((TextView) row.findViewById(R.id.rpt_sgt_type)).setText(rptType);
			((TextView) row.findViewById(R.id.rpt_sgt_subject)).setText(rptSubject);
			((TextView) row.findViewById(R.id.rpt_sgt_problem)).setText(rptProblem);
			((TextView) row.findViewById(R.id.rpt_sgt_suggest)).setText(rptSuggest);
			((TextView) row.findViewById(R.id.rpt_sgt_user)).setText(rptUser);
			((TextView) row.findViewById(R.id.rpt_sgt_owner)).setText(rptOwner);

			ImageView rptImg = (ImageView) row.findViewById(R.id.rpt_sgt_image);
			// Get Image
			if (suggestRpt.ImageFirst != null && suggestRpt.ImageFirst.length() != 0) {
				((TextView) row.findViewById(R.id.nophoto)).setVisibility(TextView.GONE);

				String imageKey = suggestRpt.ImageFirst.split(AppUtil.SEMI_COLON)[0];

				downloadCall = DownloadCall.getInstance();
				mTask = new DefaultTask(downloadCall, getString(R.string.img_url) + imageKey, rptImg);
				mTask.delegate = fragment;
				mTask.execute();

			} else {
				rptImg.setVisibility(TextView.GONE);
			}

			if (rptStation.length() != 0) {
				((TextView) row.findViewById(R.id.nophoto)).setVisibility(TextView.GONE);
			}

			// Grouping
			if (rptStation.length() != 0)
				row.setBackgroundResource(R.drawable.report_group_top);
			else
				row.setBackgroundResource(R.drawable.report_group_middle);

			if (count == suggestRptList.SuggestionReport.size() - 1)
				if (rptStation.length() != 0)
					row.setBackgroundResource(R.drawable.report_group);
				else
					row.setBackgroundResource(R.drawable.report_group_bottom);

			table.addView(row);

			count++;
		}
		table.requestLayout();

		// calculate begin - end
		int endNo = Integer.parseInt(reportCache.PageNumber) * Integer.parseInt(reportCache.PageSize);
		int beginNo = (endNo - Integer.parseInt(reportCache.PageSize)) + 1;
		if (endNo >= suggestRptList.SuggestionReport.get(0).Row_Count)
			endNo = suggestRptList.SuggestionReport.get(0).Row_Count;

		// set total page
		TextView totalpage = (TextView) getView().findViewById(R.id.total_page);
		String totalpageStr = getString(R.string.total_page);
		totalpageStr = totalpageStr.replaceAll("@0", String.valueOf(beginNo));
		totalpageStr = totalpageStr.replaceAll("@1", String.valueOf(endNo));
		totalpageStr = totalpageStr.replaceAll("@2", String.valueOf(suggestRptList.SuggestionReport.get(0).Row_Count));
		totalpage.setText(totalpageStr);

		if (currentPage == 0) {
			double doubleCount = (double) suggestRptList.SuggestionReport.get(0).Row_Count / Integer.parseInt(reportCache.PageSize);
			final int pageCount = (int) Math.ceil(doubleCount);

			for (int i = 1; i <= pageCount; i++) {
				final int noOfPage;

				noOfPage = i;
				final LinearLayout mLinearScroll = (LinearLayout) getView().findViewById(R.id.paging);
				final TextView page = new TextView(getActivity());

				LayoutParams lp = new LinearLayout.LayoutParams(50, 50);

				page.setTextColor(Color.WHITE);
				page.setText(String.valueOf(i));
				page.setGravity(Gravity.CENTER);
				page.setBackground(getResources().getDrawable(R.drawable.page_indicator));
				mLinearScroll.addView(page, lp);
				mLinearScroll.setBackgroundColor(getResources().getColor(R.color.search_bar));
				if (noOfPage == 1)
					page.setSelected(true);
				page.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// Page Selected Hilight
						for (int index = 0; index < mLinearScroll.getChildCount(); index++) {
							mLinearScroll.getChildAt(index).setSelected(false);
						}
						v.setSelected(true);

						if (noOfPage != currentPage) {
							currentPage = noOfPage;
							getPaging(Integer.parseInt(getString(R.string.page_size)), noOfPage);
						}
					}

				});
			}
			// init paging
			final PagingScrollView mScroll = (PagingScrollView) getView().findViewById(R.id.paging_scroll);

			ViewTreeObserver vto = mScroll.getViewTreeObserver();
			vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

				@Override
				public void onGlobalLayout() {
					// TODO Auto-generated method stub
					maxPage = mScroll.getChildAt(0).getMeasuredWidth() - mScroll.getMeasuredWidth();
					mScroll.getViewTreeObserver().removeGlobalOnLayoutListener(this);
				}

			});

			mScroll.setScrollViewListener(new ScrollViewListener() {

				@Override
				public void onScrollChanged(PagingScrollView scrollView, int x, int y, int oldx, int oldy) {
					// TODO Auto-generated method stub
					if (maxPage > 0) {
						ImageView mPrevious = (ImageView) getView().findViewById(R.id.previous_page);
						ImageView mNext = (ImageView) getView().findViewById(R.id.next_page);
						int max = scrollView.getChildAt(0).getMeasuredWidth() - scrollView.getMeasuredWidth();
						if (x <= 0) {
							mPrevious.setVisibility(ImageView.INVISIBLE);
							mNext.setVisibility(ImageView.VISIBLE);
						} else if (x >= max) {
							mPrevious.setVisibility(ImageView.VISIBLE);
							mNext.setVisibility(ImageView.INVISIBLE);
						} else {
							mPrevious.setVisibility(ImageView.VISIBLE);
							mNext.setVisibility(ImageView.VISIBLE);
						}
					}
				}
			});

			ImageView mPrevious = (ImageView) getView().findViewById(R.id.previous_page);
			ImageView mNext = (ImageView) getView().findViewById(R.id.next_page);

			if (pageCount > Integer.parseInt(getString(R.string.paging_size))) {
				mPrevious.setVisibility(ImageView.INVISIBLE);
				mNext.setVisibility(ImageView.VISIBLE);
			} else {
				mPrevious.setVisibility(ImageView.INVISIBLE);
				mNext.setVisibility(ImageView.INVISIBLE);
			}

		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.report_assess, container, false);
	}

	// TODO: Rename method, update argument and hook method into UI event
	public void onButtonPressed(Uri uri) {
		if (mListener != null) {
			mListener.onFragmentInteraction(uri);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		((MainActivity) activity).onSectionAttached(getArguments().getInt(AppUtil.ARG_SECTION_NUMBER));
	}

	@Override
	public void onDetach() {
		super.onDetach();
		mListener = null;
	}

	/**
	 * This interface must be implemented by activities that contain this
	 * fragment to allow an interaction in this fragment to be communicated to
	 * the activity and potentially other fragments contained in that activity.
	 * <p>
	 * See the Android Training lesson <a href=
	 * "http://developer.android.com/training/basics/fragments/communicating.html"
	 * >Communicating with Other Fragments</a> for more information.
	 */
	public interface OnFragmentInteractionListener {
		// TODO: Update argument type and name
		public void onFragmentInteraction(Uri uri);
	}

	public void getReportService(String year, String project, String cycle, String zone, String station, String type) {
		
		//Toast.makeText(getActivity(),"year : " + year + AppUtil.SPACE + "project : " + project + AppUtil.SPACE + "cycle : " + cycle + AppUtil.SPACE + "zone : " + zone + AppUtil.SPACE + "station : " + station + AppUtil.SPACE + "type : " + type, Toast.LENGTH_LONG).show();
		
		PropertyInfo pageSizeProp = new PropertyInfo();
		pageSizeProp.setName(SuggestionReport.Page_Size);
		pageSizeProp.setValue(getString(R.string.report_page_size));
		pageSizeProp.setType(Integer.class);

		PropertyInfo pageNoProp = new PropertyInfo();
		pageNoProp.setName(SuggestionReport.Page_Number);
		pageNoProp.setValue("1");
		pageNoProp.setType(Integer.class);

		PropertyInfo yearProp = new PropertyInfo();
		yearProp.setName(SuggestionReport.AssessYearId);
		yearProp.setValue(year);
		yearProp.setType(String.class);

		PropertyInfo projProp = new PropertyInfo();
		projProp.setName(SuggestionReport.ProjectId);
		projProp.setValue(project);
		projProp.setType(String.class);

		PropertyInfo cycleProp = new PropertyInfo();
		cycleProp.setName(SuggestionReport.CycleAssessId);
		cycleProp.setValue(cycle);
		cycleProp.setType(String.class);

		PropertyInfo zoneProp = new PropertyInfo();
		zoneProp.setName(SuggestionReport.SaleZoneId);
		zoneProp.setValue(zone);
		zoneProp.setType(String.class);

		PropertyInfo stationProp = new PropertyInfo();
		stationProp.setName(SuggestionReport.Station_Id);
		stationProp.setValue(station);
		stationProp.setType(String.class);

		PropertyInfo typeProp = new PropertyInfo();
		typeProp.setName(SuggestionReport.AssessUserTypeId);
		typeProp.setValue(type);
		typeProp.setType(String.class);

		reportCache.yearProp = yearProp;
		reportCache.projProp = projProp;
		reportCache.zoneProp = zoneProp;
		reportCache.stationProp = stationProp;
		reportCache.cycleProp = cycleProp;
		reportCache.typeProp = typeProp;
		reportCache.PageSize = pageSizeProp.getValue().toString();
		reportCache.PageNumber = pageNoProp.getValue().toString();

		mTask = new DefaultTask(com, getString(R.string.method_reportsuggestion));
		mTask.delegate = this;
		mTask.execute(pageSizeProp, pageNoProp, yearProp, projProp, cycleProp, zoneProp, stationProp, typeProp);

	}

	@Override
	public void processFinish(String method, Object output) {
		// TODO Auto-generated method stub
		if (method.equals(getString(R.string.method_reportsuggestion)))
			getReportSuggestion(method, output);

	}

	private void getReportSuggestion(String method, Object output) {
		// TODO Auto-generated method stub
		WidgetUtil.showProgress(mContentView, mProgressView, false);
		try {
			clearSearchAssessData();
			suggestRptList = (SuggestionReportList) gson.fromJson((String) output, SuggestionReportList.class);
			Log.i(method, "Call WS Success");

			generateReport();

			TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
			mNoData.setVisibility(TextView.GONE);
			ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);
			mHasData.setVisibility(ViewGroup.VISIBLE);

		} catch (Exception e) {
			Log.i(method, "Call WS Failed");

			Toast.makeText(getActivity(), getString(R.string.not_found), Toast.LENGTH_LONG).show();

			ViewGroup mHasData = (ViewGroup) getView().findViewById(R.id.has_data);
			mHasData.setVisibility(ViewGroup.GONE);
			TextView mNoData = (TextView) getView().findViewById(R.id.no_data);
			mNoData.setVisibility(TextView.VISIBLE);
		}

		WidgetUtil.showProgress(mContentSearchView, mProgressSearchView, false);
	}

	public void clearSearchAssess() {
		search.shipToSelected = "";

		Spinner removeSpin = (Spinner) getActivity().findViewById(R.id.year_assess);
		removeSpin.setSelection(0);

		removeSpin = (Spinner) getActivity().findViewById(R.id.div_assess);
		removeSpin.setSelection(0);

		removeSpin = (Spinner) getActivity().findViewById(R.id.type_assess);
		removeSpin.setSelection(0);

		List<String> removearr = new ArrayList<String>();
		removearr.add(getString(R.string.header_spinner));
		ArrayAdapter<String> removeAdt = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, removearr);

		removeSpin = (Spinner) getActivity().findViewById(R.id.project_assess);
		removeSpin.setAdapter(removeAdt);

		removeSpin = (Spinner) getActivity().findViewById(R.id.cycle_assess);
		removeSpin.setAdapter(removeAdt);

		removeSpin = (Spinner) getActivity().findViewById(R.id.dept_assess);
		removeSpin.setAdapter(removeAdt);

		removeSpin = (Spinner) getActivity().findViewById(R.id.zone_assess);
		removeSpin.setAdapter(removeAdt);

		AutoCompleteTextView autoComplete = (AutoCompleteTextView) getView().findViewById(R.id.station);
		autoComplete.setText("");

	}

	public void resetHeader() {
		PagingScrollView pageScroll = (PagingScrollView) getView().findViewById(R.id.paging_scroll);
		LinearLayout page = (LinearLayout) getView().findViewById(R.id.paging);

		pageScroll.scrollTo(0, 0);
		currentPage = 0;
		maxPage = 0;
		page.removeAllViews();
		page.requestLayout();

	}

	public void clearSearchAssessData() {
		suggestRptList = new SuggestionReportList();
		TableLayout table = (TableLayout) getView().findViewById(R.id.rpt_sgt_table);
		table.removeAllViews();
		table.requestLayout();

		// reset Header
		ScrollView vertical = (ScrollView) getView().findViewById(R.id.vertical_data);
		HorizontalScrollView horizontal = (HorizontalScrollView) getView().findViewById(R.id.horizontal_data);
		vertical.scrollTo(0, 0);
		horizontal.scrollTo(0, 0);
	}

	public void getPaging(int size, int number) {
		WidgetUtil.showProgress(mContentSearchView, mProgressSearchView, true);
		PropertyInfo pageSize = new PropertyInfo();
		PropertyInfo pageNumber = new PropertyInfo();

		pageSize.setName("Page_Size");
		pageSize.setValue(String.valueOf(size));
		pageSize.setType(Integer.class);

		pageNumber.setName("Page_Number");
		pageNumber.setValue(String.valueOf(number));
		pageNumber.setType(Integer.class);

		reportCache.PageSize = pageSize.getValue().toString();
		reportCache.PageNumber = pageNumber.getValue().toString();

		mTask = new DefaultTask(com, getString(R.string.method_reportsuggestion));
		mTask.delegate = this;
		mTask.execute(pageSize, pageNumber, reportCache.yearProp, reportCache.projProp, reportCache.cycleProp, reportCache.zoneProp, reportCache.stationProp, reportCache.typeProp);

	}

	@Override
	public void processFinish(String method, Object output, Object... objects) {
		// TODO Auto-generated method stub
		try {
			if (method.startsWith(getString(R.string.img_url))) {
				DownloadImage(method, output, objects);
			}
		} catch (Exception e) {
		}

	}

	private void DownloadImage(String method, Object output, Object[] objects) {
		// TODO Auto-generated method stub
		try {
			ImageView img = (ImageView) objects[0];
			img.setImageBitmap((Bitmap) output);
		} catch (Exception e) {
			Log.i("Image Error", e.toString());
		}

	}
}
